<!-- 搜索项目 -->
<template>
  <h-select-input-popup
    ref="hSelectInputPopup"
    v-model="val"
    v-bind="$attrs"
    v-on="$listeners"
    :params="queryParams"
    :keywords.sync="keywords"
    :getList="getList"
    :useSearch="false"
    :isUnique="true"
    :isMulti="muitFlag"
    @getDetail="getDetail"
    @change="$emit('change', $event)"
  >
    <template v-slot:default="{ item }">
      <view class="project-item">
        <view class="option">
          <view class="lf">项目负责人</view>
          <view class="rl">{{ item.name?item.name:item.id }}</view>
        </view>
        <!-- <view class="option">
          <view class="lf">项目负责人编号</view>
          <view class="rl">{{ item.id }}</view>
        </view> -->
      </view>
    </template>
  </h-select-input-popup>
</template>

<script>
import { erpOmcProjectTaskFinalList } from '@/api/index.js'
import { filterMultiDictText } from '@/utils/JDictSelectUtil.js'

export default {
  name: 'HSelectExemptionObjectsInputPopup',
  data() {
    return {
      getList: erpOmcProjectTaskFinalList,
      params: {
        // column: 'createTime',
        // order: 'desc',
        pageNo: 1,
        // pageSize: 10,
        // docBigCategory: '',
        // docSmallCategory: '',
        // field: 'id,,,billNo,docBigCategory_dictText,docSmallCategory_dictText,teamId_dictText,classification_dictText,voucherNumberRange,totalNumber,docAddress',
      },
      keywords: '',
    }
  },
  // model: {
  //   prop: 'value',
  //   event: 'input',
  // },
  props: {
    value: {
      type: [String, Number, Array],
      default: null,
    },
    muitFlag: {
      type: Boolean,
      default: false,
    },
    projectId: {
      type: String,
      default: '',
    },
    dictOptions: {
      type: Object,
      default: () => {},
      required: false,
    },
  },
  computed: {
    val: {
      get() {
        return this.value
      },
      set() {
        this.$emit('input', this.value)
      },
    },
    queryParams() {
      const params = {
        ...this.params,
      }
      params.projectId = this.projectId
      // if (this.keywords) {
      //   params.projectId = '*' + this.keywords + '*'
      // }
      return params
    },
  },
  watch: {
    projectId: {
      handler(id) {
        this.$set(this.params, 'projectId', id)
      },
      deep: true,
    },
  },
  methods: {
    // 获取详情
    getDetail(value) {
      if (value instanceof Array) {
        this.$emit('select', {
          data: '',
          id: '',
        })
        return
      }

      let projectLeadingTemp = []
      let empIdArr = value.split(',')
      empIdArr.map((item, ind) => {
        if (item) {
          projectLeadingTemp.push(filterMultiDictText(this.dictOptions['empId'], item + ''))
        }
      })
      const title = projectLeadingTemp.join(',')
      this.$emit('select', {
        data: title,
        id: value,
      })
      this.$nextTick(() => {
        this.$refs.hSelectInputPopup.title = title
      })
      // erpOaDocBaseInfoById({ id: value }).then((res) => {
      //   if (res.success) {
      //     this.$refs.hSelectInputPopup.title = res.result.billNo
      //     this.$emit('select', {
      //       data: res.result,
      //       id: value,
      //     })
      //   }
      // })
    },
  },
}
</script>

<style lang="scss" scoped>
// 按钮
.btn {
  position: fixed;
  bottom: 20rpx;
  width: 95%;
}
</style>
